import axios from "axios";
import * as echarts from "echarts";
const url = import.meta.env.VITE_backurl;
const urlAstar = import.meta.env.VITE_backurl_astar;

export const getPortListByCountry = (country) => {
  return axios.get(url + "/port/getPortListByCountry?country=" + country);
};

export const getCountryAndCount = () => {
  return axios.get(url + "/port/getCountryAndCount");
};

export const initChartPie = (data, dom) => {
  let option = {
    legend: {
      top: "bottom",
    },
    title: {
      text: "港口分布图",
      left: "center",
    },
    tooltip: {
      trigger: "item",
    },
    series: [
      {
        type: "pie",
        radius: [20, 100],
        center: ["50%", "50%"],
        // roseType: "area",
        itemStyle: {
          borderRadius: 8,
        },
        data: data.map((item) => {
          return {
            name: item.country_cn,
            value: item.count,
          };
        }),
      },
    ],
  };
  let myChart = echarts.init(dom);
  myChart.setOption(option);
};

export const getAstarLine = (data) => {
  return axios({
    method: "post",
    url: urlAstar + "/star/ht",
    data: {
      start: data.start,
      end: data.end,
    },
  });
};

export const getAstarLineA = (data) => {
  return axios({
    method: "post",
    url: urlAstar + "/star/a",
    data: {
      start: data.start,
      end: data.end,
    },
  });
};

export const exportXlsx = (data) => {
  return axios({
    method: "post",
    url: url + "/star/exportXlsx",
    data: {
      title: data.title,
      data: data.data,
    },
  });
};

export const getFile = (data) => {
  return axios({
    method: "get",
    responseType: "blob",
    url: url + data.name,
  });
}

export const uploadCsv = (data) => {
  return axios({
    method: "post",
    url: url + "/upload/uploadCsv",
    data: data
  });
}

// outpng
export const getOutpng = (data) => {
  return axios({
    method: "post",
    url: urlAstar + "/base/outpng",
    data: data
  });
}

// getOutJson
export const getOutJson = (data) => {
  return axios({
    method: "post",
    url: urlAstar + "/base/outjson",
    data: data
  });
}